// pages/admin-home/admin-home.js 
const app = getApp()
Page({

  /** 
   * 页面的初始数据 
   */
  data: {
    params: { page: 1 },
    params1: { page: 1 },
    params2: { page: 1 },
    params3: { page: 1 },
    active: 0,
    topFilter: '1067246875800000066',
    topFilter1: '1067246875800000066',
    topFilter2: '1067246875800000066',
    topFilter3: '1067246875800000066',
  },

  /** 
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
     
  },
  
  loadMore(e) {
    let { params, foodList } = this.data
    this.setData({
      'params.page': params.page + 1,
    
    }, () => {
      app.reqFetch.pageAdmin({
        ...this.data.params,
        canteenId: this.data.topFilter
      }, (res) => {
        const { list = [] } = res.list
        this.setData({
          foodList: foodList.concat(list)
        })
      })
    })
  },
  loadMore1(e) {
    let { params1, foodList1 } = this.data
    this.setData({
      'params1.page': params1.page + 1,
     
    }, () => {
      app.reqFetch.collarpageAdmin({
        ...this.data.params1,
        canteenId: this.data.topFilter1
      }, (res) => {
        const { list = [] } = res.list
        this.setData({
          foodList1: foodList1.concat(list)
        })
      })
    })
  },
  loadMore2(e) {
    let { params2, foodList2 } = this.data
    this.setData({
      'params2.page': params2.page + 1,
    }, () => {
      app.reqFetch.auxiliarymateriPageAdmin({
        ...this.data.params2,
        canteenId: this.data.topFilter2
      }, (res) => {
        const { list = [] } = res.list
        this.setData({
          foodList2: foodList2.concat(list)
        })
      })
    })
  },
  loadMore3(e) {
    let { params3, foodList3 } = this.data
    this.setData({
      'params3.page': params3.page + 1,
      
    }, () => {
      app.reqFetch.smallcanteenpurchasepageAdmin({
        ...this.data.params3,
        canteenId: this.data.topFilter
      }, (res) => {
        const { list = [] } = res.list
        this.setData({
          foodList3: foodList3.concat(list)
        })
      })
    })
  },

  /** 
   * 生命周期函数--监听页面初次渲染完成 
   */
  onReady: function () {

  },

  /** 
   * 生命周期函数--监听页面显示 
   */
  onShow: function () {

    this.getList()
    this.getList1()
    this.getList2()
    this.getList3()
  },

  /** 
   * 生命周期函数--监听页面隐藏 
   */
  onHide: function () {

  },

  /** 
   * 生命周期函数--监听页面卸载 
   */
  onUnload: function () {

  },

  /** 
   * 页面相关事件处理函数--监听用户下拉动作 
   */
  onPullDownRefresh: function () {

  },

  /** 
   * 页面上拉触底事件的处理函数 
   */
  onReachBottom: function () {

  },

  /** 
   * 用户点击右上角分享 
   */
  onShareAppMessage: function () {

  },
  onChange(event) {
    if (event.detail === 1) {
      wx.redirectTo({
        url: '/pages/mine/mine',
      })
    }
  },


  changeFilter(e){
    const { type } = e.currentTarget.dataset
    this.setData({ topFilter:type},()=>{
      this.getList()
    })
  },
  changeFilter1(e) {
    const { type } = e.currentTarget.dataset
    this.setData({ topFilter1: type }, () => {
      this.getList1()
    })
  },
  changeFilter2(e) {
    const { type } = e.currentTarget.dataset
    this.setData({ topFilter2: type }, () => {
      this.getList2()
    })
  },
  changeFilter3(e) {
    const { type } = e.currentTarget.dataset
    this.setData({ topFilter3: type }, () => {
      this.getList3()
    })
  },

  getList(){
    app.reqFetch.pageAdmin({
      canteenId:this.data.topFilter
    }, (res) => {
      const { list ,pending } = res
      this.setData({
        foodList: list.list,
        pending: pending,
        'params.page': 0,
      })
    })
  },

  getList1() {
    app.reqFetch.collarpageAdmin({
      canteenId: this.data.topFilter1
    }, (res) => {
      const { list ,pending } = res
      this.setData({
        foodList1: list.list,
        pending1: pending,
        'params1.page': 0,
      })
    })
  },

  getList2() {
    app.reqFetch.auxiliarymateriPageAdmin({
      canteenId: this.data.topFilter2
    }, (res) => {
      const { list ,pending } = res
      this.setData({
        foodList2: list.list,
        pending2: pending,
        'params2.page': 0,
      })
    })
  },

  getList3() {
    app.reqFetch.smallcanteenpurchasepageAdmin({
      canteenId: this.data.topFilter3
    }, (res) => {
      const { list ,pending } = res
      this.setData({
        foodList3: list.list,
        pending3: pending,
        'params3.page': 0,
      })
    })
  },


  toDetails(e) {
    const { stockOrderId, auxiliaryMaterialsId, smallCanteenPurchaseId, collarId, status } = e.currentTarget.dataset.record
    const type = e.currentTarget.dataset.type

    const orderId={
      stockOrderId,
      auxiliaryMaterialsId,
      collarId,
      smallCanteenPurchaseId
    }
    
    if (status === 1) {
      wx.navigateTo({
        url: '/pages/admin-purchase-list/admin-purchase-list?data=' + JSON.stringify({ ...orderId, type, aduit: true }),
      })
    } else if (status === 2) {
      wx.navigateTo({
        url: '/pages/admin-purchase-list/admin-purchase-list?data=' + JSON.stringify({ ...orderId, chenck: true, type}),
      })
    } else {
      wx.navigateTo({
        url: '/pages/admin-purchase-list/admin-purchase-list?data=' + JSON.stringify({ ...orderId, isQuote: true, type}),
      })
    }

  },
  onChange(event) {
    if (event.detail === 1) {
      wx.redirectTo({
        url: '/pages/mine/mine',
      })
    }
  },

})